package jgl.vajra.management.part.home.fragment;

import android.graphics.Color;
import android.view.View;

import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.TimePickerView;
import com.orhanobut.logger.Logger;

import java.util.Date;

import jgl.vajra.management.R;
import jgl.vajra.management.databinding.FragmentTaskPageBinding;
import jgl.vajra.management.dialogFragment.RuleDescriptionDialogFragment;
import jgl.vajra.management.manager.IntentManager;
import jgl.vajra.management.part.home.contract.TaskPageContract;
import jgl.vajra.management.part.home.pop.AccountingMethodPop;
import jgl.vajra.management.part.home.viewModel.TaskPageViewModel;
import jgl.vajra.management.widget.mvvm.factory.CreateViewModel;
import jgl.vajra.management.widget.mvvm.view.BaseMVVMFragment;
import jgl.vajra.management.widget.utils.PhoneUtils;
import jgl.vajra.management.widget.utils.TimeUtils;
import jgl.vajra.management.widget.utils.UIUtils;

@CreateViewModel(TaskPageViewModel.class)
public class TaskPageFragment extends BaseMVVMFragment<TaskPageViewModel, FragmentTaskPageBinding> implements TaskPageContract.View {

    private RuleDescriptionDialogFragment ruleDescriptionDialogFragment;
    private AccountingMethodPop accountingMethodPop;

    @Override
    public int getLayoutId() {
        return R.layout.fragment_task_page;
    }

    @Override
    public void initView() {
        mBinding.setView(this);

        Logger.d("获取UDID" + PhoneUtils.getUDID());
    }

    @Override
    public void initData() {

    }

    @Override
    public void initEvent() {

    }

    //规则说明
    @Override
    public void onRuleDescription() {
        if (ruleDescriptionDialogFragment == null)
            ruleDescriptionDialogFragment = new RuleDescriptionDialogFragment();
        ruleDescriptionDialogFragment.show(mActivity.getSupportFragmentManager());
    }

    //接单区域
    @Override
    public void onReceivingArea() {
        IntentManager.toReceivingAreaActivity(mActivity);
    }

    //我的豪车
    @Override
    public void onMyCar() {

    }

    //开始时间
    @Override
    public void onTimeStart() {
        //时间选择器
        TimePickerView pvTime = new TimePickerBuilder(mActivity, new OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {
                //Logger.d(date.toString() + "时间啊"+ TimeUtils.getParseDayTextTime(date));
                mBinding.tvTimeStart.setText(TimeUtils.getParseDayTextTime(date));
                mBinding.tvTimeStart.setTextColor(UIUtils.getColor(R.color.color_333333));
            }
        })
                .setTitleText("开始时间")//标题文字
                .setTitleColor(Color.BLACK)//标题文字颜色
                .setTitleSize(18)//标题文字大小
                .setType(new boolean[]{true, true, true, true, false, false})// 默认全部显示
                .setLabel("年", "月", "日", "时", "分", "秒")//默认设置为年月日时分秒
                .isCenterLabel(true) //是否只显示中间选中项的 label 文字，false 则每项 item 全部都带有 label。
                .build();
        pvTime.show();
    }

    //结束时间
    @Override
    public void onTimeEnd() {
        //时间选择器
        TimePickerView pvTime = new TimePickerBuilder(mActivity, new OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {
                //Logger.d(date.toString() + "时间啊"+ TimeUtils.getParseDayTextTime(date));
                mBinding.tvTimeEnd.setText(TimeUtils.getParseDayTextTime(date));
                mBinding.tvTimeEnd.setTextColor(UIUtils.getColor(R.color.color_333333));
            }
        })
                .setTitleText("开始时间")//标题文字
                .setTitleColor(Color.BLACK)//标题文字颜色
                .setTitleSize(18)//标题文字大小
                .setType(new boolean[]{true, true, true, true, false, false})// 默认全部显示
                .setLabel("年", "月", "日", "时", "分", "秒")//默认设置为年月日时分秒
                .isCenterLabel(true) //是否只显示中间选中项的 label 文字，false 则每项 item 全部都带有 label。
                .build();
        pvTime.show();
    }

    //算账方式
    @Override
    public void onSettleAccounts() {
        if (accountingMethodPop == null)
            accountingMethodPop = new AccountingMethodPop(mActivity);
        accountingMethodPop.showPopupWindow(mBinding.getRoot());
    }

    //接单设置
    @Override
    public void onReceivingSetting() {
        IntentManager.toReceivingSettingActivity(mActivity);
    }

    @Override
    public void onAgreeCheck() {

    }
}
